package ej_lig.com.uw.bo;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;

import ej_lig.com.ConnectionPool;
import ej_lig.com.JdbcUtil;
import ej_lig.com.LogWriter;
import ej_lig.com.uw.dao.MessageDao;
import ej_lig.com.uw.dto.TestDTOList;

public class TestBo {

	private static TestDTOList testDTOList;

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		Connection conn = null;
		
		try {
			//set connection from ConnectionPool class.
			conn = ConnectionPool.getConnection();	
			
			int  limitCnt = 100;
			
			//write result to the file.
			PrintStream out = new PrintStream(new FileOutputStream("D:/OutFile4.csv"));	
			
			MessageDao messageDao =	MessageDao.getInstnace();
			MessageDao messageDao2 = MessageDao.getInstnace();
			
			TestDTOList testDTOList1 = messageDao.select(conn, limitCnt);		
			
			
			int dtoCnt = testDTOList1.getDtoList().size();
			for(int idx = 0;idx<dtoCnt;idx++)
			{				
				
				TestDTOList testDTOList2 = messageDao2.select2(conn, testDTOList1.getDtoList().get(idx).getTable_Name(), 
																			testDTOList1.getDtoList().get(idx).getColumn_Name());
				
				////////////////////////////////////////
				int dtoCnt2 = testDTOList2.getDtoList().size();
				for(int idx2 = 0;idx2<dtoCnt2;idx2++)
				{
					out.println(testDTOList2.getDtoList().get(idx2).getTable_Name()
									+"|"+testDTOList2.getDtoList().get(idx2).getColumn_Name()
									+"|"+testDTOList2.getDtoList().get(idx2).getCount());				
				}
				
				System.out.println(testDTOList1.getDtoList().get(idx).getTable_Name()+" / "+testDTOList1.getDtoList().get(idx).getColumn_Name()+" is completed...");
			}
			
			
		} catch (SQLException e) {
			LogWriter.out("SQLException : " +e.getMessage());
			throw new SQLException(e);
		} catch (Exception e) {	
			LogWriter.out("Exception : " +e.getMessage());	
			
			
			throw new Exception(e);
		} finally {
			JdbcUtil.close(conn);			
		}
		
		System.out.println("Process is completed!!!");
	}


}
